<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.autotab.js"></script>															
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.form.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.validate.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/cmxforms.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.metadata.js"></script>
<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.alphanumeric.pack.js"></script>


<!--begin add code by D-Ngan April 1-->
<script type="text/javascript">
$.metadata.setType("attr", "validate");
$(document).ready(function() {
	//$('#price').autotab({ target: 'price', format: 'pricea', previous: 'price' });
	$("#form").validate({
		rules:{
				catalog_child: "required",
				catalog_parent: "required",
				price:{
					required: false,
      				digits: false
				},
				shop_name:{
					required: true,
					minlength:3,
					maxlength:50
				},
				name:{
					required: true,
					minlength:3,
					maxlength:100
				},
				address:{
					required:true,
					minlength:12,
					maxlength:255
				},
				image:{
					accept:"gif|jpg|jpeg|pjpeg|png|x-png"
				},
				detail_info:{
					required:false,
					minlength:0
				}
			},
		messages: {
			catalog_child: "Chọn Danh Mục Sản Phẩm",
			catalog_parent: "Chọn Danh Mục Sản Phẩm",
			price:{
				required:"Nhập Giá Sản Phẩm",
				digits:"Giá Sản Phẩm Phải Là Một Số"
			},
			image:{
				accept:"Chỉ Nhập Định Dạng .gif|jpg|jpeg|pjpeg|png|x-png"
			},
			address:{
				required:"Nhập địa chỉ shop",
				minlength:"Tối thiểu 12 ký tự",
				maxlength:"Tối đa 255 ký tự"
			},
			shop_name: {
				required:"Nhập tên shop",
				minlength:"Tối thiểu 3 ký tự",
				maxlength:"Tối đa 30 ký tự"
			},
			name: {
				required:"Nhập tên sản phẩm",
				minlength:"Tối thiểu 3 ký tự",
				maxlength:"Tối đa 100 ký tự"
			},
			detail_info:{
				required:"Nhập Thông Tim Mô Tả Thông Tin Sản Phẩm",
				minlength:"Thông Tin Sản Phẩm Tối Thiểu 12 Ký Tự"
			}
		}
	});
});
</script>

<style type="text/css">
	.cmxform .upload div  {
		width: 760px;
		margin-left: 30px;
		padding-top: 5px;
	}
	.cmxform .upload .rows{
		clear:both;
	}
	.cmxform .upload .rows .title {
		height: 20px;
		width: 710px;
		color: #656565;
		font-size:1em;
		font-weight:bold;
		border-color:black;
		background: #F0F3F7;
		border:1px solid #D8DFEA;
		padding:5px 0px 5px 0px;
	}

	.cmxform .upload .rows .title label {
		color:#2A00AA;
		font-size:1.2em;
		font-weight:bold;
		text-transform:uppercase;
	}

	.items {
		float:left;
		height: 20px;
	}
	.input_textbox{
	}

	#image{
		margin-left:30px;
		height: 23px;
		width: 500px;
		color: black;
	}
	.items .error{
		float:left;
		margin-left:10px;
	}


    #payment_sub {
    	display: none;
    }
    .block { display: block; }
	.selection_items{
		font-size:16px;
		height:30px;
		
	}
	.selection_items:hover{ 	
		background-color:#0FF;
	}
	.selection_items:active{
		
		border:1px solid;
		border-color:#00F;
		background-color:#0FF;
	}

</style>

<style type="text/css">
#form { width: 00px; }
#form label {
	width: 250px;
	text-align: left;
}
#form label.error, #form input.submit { margin-left: 253px; }
#form { width: 670px; }
#form label.error {
	margin-left: 10px;
	width: auto;
	display: inline;
}

#newsletter_topics label.error {
	display: none;
	margin-left: 103px;
}
#form div .upload #product_description .entry div table tr td {
	text-align: left;
}
#form div .upload #product_description .entry div table {
	text-align: left;
}
</style>

<form method="post" name="form" enctype="multipart/form-data" class="cmxform" id="form" action="<?php echo $action; ?>">
<div style="width: 85%; height:100%;  margin-left: 70px;">
  <input type="hidden" name="parent_catalog" id="parent_catalog" value="<?php echo $pa_catalog_id; ?>" />
<input type="hidden" name="child_catalog" id="child_catalog" value="<?php echo $cr_catalog_id; ?>" />
<input type="hidden" name="product_id" id="product_id" value="<?php echo $product_id; ?>" />
<input type="hidden" name="old_image" id="old_image" value="<?php echo $old_image; ?>" />

<div class="upload" style="float:left; border: 1px solid #DDDDDD; width: 800px; margin-left: 10px; padding: 10px; background-color: #F6F9FF">
	<div style="border-bottom: 1px solid #EA6F1F;margin-bottom: 15px; padding-bottom: 0px; position: relative;">
         <div style="padding-bottom: 10px; text-transform:uppercase; color: #656565;font-size: 16px;font-weight: bold;">
                        <b>Sửa bản Tin</b>
        </div>
      </div> <!--Tieu dề--><!--End tieu de-->
        <div class="rows" style="height: 40px;">
                    <div class="title">
                        <span  style="float:left; color:#007F00; margin-left:10px; font-size:14px; text-transform:uppercase" >Hình thức</span>
                        <span style="float:right; margin-right:350px;U">
                        <?php if($sale_flg == 1){ ?>
                            <input type="radio" style="width: 10px;" onClick="doShow();" checked="checked" id="sale_flg1" value="1" name="sale_flg"  /> Đăng Bán
                        <?php } else { ?>
                            <input type="radio" style="width: 10px;" onClick="doShow();" id="sale_flg1" value="1" name="sale_flg"  /> Đăng Bán
                        <?php } ?>
                        <?php if($sale_flg == 2){ ?>
                            <input type="radio" style="width: 10px" id="sale_flg2" checked="checked" onClick="doHide();" value="2" name="sale_flg"  /> Đăng Mua
                        <?php } else { ?>
                            <input type="radio" style="width: 10px" id="sale_flg2" onClick="doHide();" value="2" name="sale_flg"  /> Đăng Mua
                        <?php } ?>
                        </span >
                    </div>
      </div><!--Bán hay mua-->
         <div id="product_description" class="rows" style="height: 280px;">
            <div class="title">
                <label for="product">Thông tin sản phẩm</label>
            </div>
            <div class="entry" style="clear: both; ">
             
        <table width="775" height="245" border="0px">
                      <tr>
                        <td width="173" rowspan="6"><img  src="<?php echo $image ?>" width="168" height="174"/></td>
                        <td width="139" height="25">Tiêu đề tin (*):</td>
                        <td width="449"><input class="items"  id="name" name="name" size="40" value="<?php echo $productInfo['name']; ?>" /></td>
                      </tr>
                      <tr>
                        <td height="25">Giá sản phẩm
                        :</td>
                        <td> <input id="price" onKeyUp="return auto_currency('price');" value="<?php echo $price; ?>" name="price" style="text-align:right" />
                          <span class="titl1" style="clear: both; padding-right: 4px;">
                          <select name="price_type" id="price_type" style="width: 60px; height: 20px; margin-left: 5px;" >
                            <option value="VN" selected="selected">VND</option>
                            <option value="USA">USA</option>
                          </select>
                        </span></td>
                      </tr>
                      <tr>
                        <td height="25"><span style="clear: both;"><span class="items"> Phạm vi đăng: </span></span></td>
                        <td><select name="zone_id" id="zone_id">
                          <?php foreach ($areas as $area) { ?>
                          <option value="<?php echo $area['zone_id']; ?>" <?php if( $zone_id == $area['zone_id']) echo "selected";?>  > <?php echo $area['name']; ?></option>
                          <?php } ?>
                        </select></td>
                      </tr>
                      <tr>
                        <td height="25"><span class="pay">
                        Hình thức thanh toán :</span></td>
                        <td >
                        <input type="radio" style="width: 15px;" class="pay" id="payment1" <?php if( $payment_id == 1) echo "checked=checked"; ?> value="1" name="payment"/>
                        <span class="pay">
                        Xem hàng và trả tiền trực tiếp</span>
                        </td>
                      </tr>
                      <tr>
                        <td height="40">&nbsp;</td>
                        <td >
                        <input type="radio" style="width: 15px" class="pay" id="payment2" <?php if( $payment_id == 2) echo "checked=checked"; ?> value="2" name="payment"  />						<span class="pay">
                        Chuyển tiền trước nhận hàng sau</span></td>
                      </tr>
                      <tr>
                        <td height="25">&nbsp;</td>
                      <td ><input type="radio" style="width: 15px" class="pay" id="payment3" value="3" <?php if( $payment_id == 3) echo "checked=checked"; ?> name="payment"  /><span class="pay">
                            Đặt hàng trước, 3 ngày sau nhận hàng </span></td>
                      </tr>
                      <tr>
                        <td height="25"><span style="margin-left:60px;">Hình ảnh</span></td>
                        <td height="25">&nbsp;	</td>
                        <td > 
                        <input type="radio" style="width: 15px" class="pay" id="payment4" value="4" <?php if( $payment_id == 4) echo "checked=checked"; ?> name="payment"  /><span class="pay">
                        Xem hàng và trả tiền trực tiếp hoặc chuyển tiền trước nhận hàng sau </span></td>
                      </tr>
                      <tr>
                        <td height="25" colspan="3">
                          <input type="file" id="image" name="image"  /></td>
                      </tr>
              </table>
           </div>
        </div><!--Chi tiet san pham-->
        
        <div id = "expand_head_1" class="rows" style="height: 380px;">
            <div class="title">
            	<span style="float:left">
                <label for="product">Chọn danh mục</label>
                </span>
                <span style="float:right">
                <input  name="expand1" type="button" value="<<" onClick="doExpand(1);">
                </span>
            </div>
            <div id="expand_row1" >
             <div style="margin-left:90px;float:left; width:260px;">
                      <select name="catalog_parent" id="catalog_parent" onchange="loadChildCatalog(this.value);doSumary(0);" style="width:250px;" size="10" >
                  <?php foreach ($parent_catalog as $catagory) { ?>
                        <?php if( $pa_catalog_id == $catagory['catalog_id']) { ?>
                            <option class="selection_items"  value="<?php echo $catagory['catalog_id']; ?>" selected="selected" ><?php echo $catagory['name']; ?></option>
                        <?php } else { ?>
                            <option class="selection_items"  value="<?php echo $catagory['catalog_id']; ?>"><?php echo $catagory['name']; ?></option>
                        <?php } ?>
                  <?php } ?>
              </select>
            </div>
            <div id="catalog_child1" style="float:left; width:260px;" >
                        <select disabled="disabled" name="catalog_child" id="catalog_child" style="width:250px;" onchange="doSumary(this.value);">
                    <option value="">Chọn danh mục cấp 2</option>
                </select>
            </div>
            </div>
        </div><!--Nganh hang-->
        
        <div id="expand_head_2" class="rows" style="height:300px">
            <div class="title">
            	<span style="float:left">
                	<label for="user">Thông tin chi tiết</label>
              </span>
                <span style="float:right">
                	<input name="expand2" type="button" value="<<" onClick="doExpand(2);">
                </span>
            </div>
            <div id="expand_row2" class="items">
                <textarea id="detail_info" name="detail_info" rows="15" cols="120" style="width: 600px; margin-left: 50px; color: black">
                    <?php echo $description; ?>
                </textarea>
            </div>
        </div><!--The Chi tiet-->
        <div class="rows">
            <div class="entry">
            	
                <input class="button" style="margin-left:250px;" type="submit" value="Lưu thay đổi"/>
            </div>
        </div>
	</div>
</div>
</form>
</body>
</html>
<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.form.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery.php.js"></script>
<script type="text/javascript" src="catalog/view/javascript/fckeditor/fckeditor.js"></script>


<script type="text/javascript">

var sBasePath = document.location.href.replace(/index\.php.*/, 'catalog/view/javascript/fckeditor/');
var oFCKeditor          = new FCKeditor('detail_info');
	oFCKeditor.BasePath = sBasePath;
	oFCKeditor.Value	   = $("#detail_info").val();
	$("#detail_info").val = "dsfdsfds";
	oFCKeditor.Value	= "";
	oFCKeditor.Width    = '620';
	oFCKeditor.Height   = '250';
	oFCKeditor.ReplaceTextarea();
</script>
<script language="JavaScript" type="text/javascript">
var url = "http://localhost/99xu/index.php?route=upload/product/insert";
formAjax = function () {
   // do an ajax post request
    $.ajax({
       // AJAX-specified URL
       url: url,
       // JSON
       dataType: 'json',
       type: "POST",
       data: $('form#form').formToArray(true),
       /* Handlers */
       // Handle the beforeSend event
       beforeSend: function(){
           return php.beforeSend();
       },
       // Handle the success event
       success: function(data, textStatus){
       	   document.location.href="http://localhost/99xu/index.php?route=product/product&product_id="+data.product_id;
           //return php.success(data, textStatus);
       },
       // Handle the error event
       error: function (xmlEr, typeEr, except) {
           return php.error(xmlEr, typeEr, except);
       },
       // Handle the complete event
       complete: function (XMLHttpRequest, textStatus) {
           return php.complete(XMLHttpRequest, textStatus);
       }
    });
    return false;
}
doExpand(1);
doExpand(2);
function doExpand(value){
	if(value==1){
		if(document.form.expand1.value=="<<"){
			$('#expand_row1').hide();
			$("#expand_head_1").attr("style","height:50px");
			document.form.expand1.value=">>"
		}
		else{
			$('#expand_row1').show();
			$("#expand_head_1").attr("style","height:380px");
			document.form.expand1.value="<<"
			
		}
	}
	else{
		if(document.form.expand2.value=="<<"){
			$('#expand_row2').hide();
			$("#expand_head_2").attr("style","height:50px");
			document.form.expand2.value=">>"
		}
		else{
			$('#expand_row2').show();
			$("#expand_head_2").attr("style","height:300px");
			document.form.expand2.value="<<"
		}
	}
}

function doHide(){
	$(".pay").hide();
	
	
}
function doShow(){
	$(".pay").show();

	
}

function auto_currency(id){
	var price_type = $('#price_type').val();
	var variable = document.getElementById(id);
	if(price_type == 'VN'){
    	var new_value =  variable.value.replace(/\./g,"");
	}else{
		var new_value =  variable.value;
	}
    variable.style.textAlign = "right";
    variable.value = digit_grouping(new_value);
}
function digit_grouping(nStr){
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + '.' + '$2');
    }
   return x1 + x2;
}

$('#price').numeric({allow:"."});
$('#shop_name').alphanumeric();
var parent_catalog = $('#parent_catalog').val();
var child_catalog  = $('#child_catalog').val();

function loadChildCatalog(value){
	$('#catalog_child1').load('index.php?route=upload/product/childCatalogories&catalog_id=' + value,{ name : this.value });
}
function loadChildCatalog1(value1, value2){
	$('#catalog_child1').load('index.php?route=upload/product/childCatalogories&cr_catalog_id='+ value2 +'&catalog_id=' + value1);
}
<!--End add code by D-Ngan April 1-->
loadChildCatalog1(parent_catalog, child_catalog);
</script>